import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

//根据js文件，自动装载路由模块
let routes = [];
const requireComponent = require.context('.', false, /\.js$/);
requireComponent.keys().forEach(fileName => {
  if (fileName !== './index.js') {
    const componentConfig = requireComponent(fileName);
    routes.push(...componentConfig.default);
  }
});

const router = new VueRouter({
  mode: 'history',
  routes
});

Vue.router = router;

//路由拦截
router.beforeEach(async (to, from, next) => {
  next();
});


export default router;

export const ALL_ROUTE = routes;
